package com.zrwl.poscloud.xo.service.impl;
import com.zrwl.poscloud.base.entity.Demo;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.base.superI.SuperServiceImpl;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.utils.StringUtils;
import com.zrwl.poscloud.xo.global.MessageConf;
import com.zrwl.poscloud.xo.global.SQLConf;
import com.zrwl.poscloud.xo.global.SysConf;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import com.zrwl.poscloud.xo.mapper.DemoMapper;
import com.zrwl.poscloud.xo.service.DemoService;
import com.zrwl.poscloud.xo.vo.DemoVO;
/**
 * 演示 服务实现类
 *
 * @author 刘思童 AutoGenerate
 * @date 2022-09-05
 */
@Service
public class DemoServiceImpl extends SuperServiceImpl<DemoMapper,Demo> implements DemoService {

    @Autowired
    private DemoService demoService;
    @Override
    public IPage<Demo> getPageList(DemoVO demoVO){
       QueryWrapper<Demo> queryWrapper = new QueryWrapper<>();
       if (StringUtils.isNotEmpty(demoVO.getKeyword()) && !StringUtils.isEmpty(demoVO.getKeyword().trim())) {
            queryWrapper.like("name", demoVO.getKeyword().trim());
       }
       Page<Demo> page = new Page<>();
       page.setCurrent(demoVO.getCurrentPage());
       page.setSize(demoVO.getPageSize());
       queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
       queryWrapper.orderByDesc(SQLConf.CREATE_TIME);
       IPage<Demo> pageList = demoService.page(page, queryWrapper);
       List<Demo> list = pageList.getRecords();
       pageList.setRecords(list);
       return pageList;
}
    @Override
    public List<Demo> getAllList(DemoVO demoVO){
        QueryWrapper<Demo> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
        queryWrapper.orderByAsc(SQLConf.CREATE_TIME);
        List<Demo> list = demoService.list(queryWrapper);
        return list;
}
    @Override
    public String add(DemoVO demoVO){
        Demo entity = new Demo();
        BeanUtils.copyProperties(demoVO, entity, SysConf.STATUS);
        entity.insert();
        demoVO.setUid(entity.getUid());
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);}
    @Override
    public String edit(DemoVO demoVO){
        Demo entity = demoService.getById(demoVO.getUid());
        BeanUtils.copyProperties(demoVO, entity);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
    @Override
    public String delete(DemoVO demoVO){
        Demo entity = demoService.getById(demoVO.getUid());
        entity.setStatus(EStatus.DISABLED);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
}
